package com.efounder.adapter;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Paint;
import android.os.Bundle;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.util.DisplayMetrics;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.alibaba.android.vlayout.layout.FixLayoutHelper;
import com.alibaba.android.vlayout.layout.FloatLayoutHelper;
import com.alibaba.android.vlayout.layout.GridLayoutHelper;
import com.alibaba.android.vlayout.layout.LinearLayoutHelper;
import com.alibaba.android.vlayout.layout.OnePlusNLayoutHelper;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseViewHolder;
import com.efounder.activity.MallCartOrderActivity;
import com.efounder.activity.MallWebViewActivity;
import com.efounder.activity.ProductDetailsActivity;
import com.efounder.addressselector.BottomDialog;
import com.efounder.addressselector.OnAddressSelectedListener;
import com.efounder.addressselector.RightDialog;
import com.efounder.addressselector.model.City;
import com.efounder.addressselector.model.County;
import com.efounder.addressselector.model.Province;
import com.efounder.addressselector.model.Street;
import com.efounder.bean.BaseItem;
import com.efounder.bean.CartStore;
import com.efounder.bean.ItemList;
import com.efounder.constant.EnvironmentVariable;
import com.efounder.mobilemall.R;
import com.efounder.thirdpartycomps.banner.Banner;
import com.efounder.thirdpartycomps.banner.BannerConfig;
import com.efounder.thirdpartycomps.banner.Transformer;
import com.efounder.thirdpartycomps.banner.listener.OnBannerListener;
import com.efounder.utils.GlideImageLoader;
import com.efounder.utils.MallRequestUtil;
import com.efounder.utils.ResStringUtil;
import com.efounder.view.MyExpandableListView;
import com.efounder.view.countdownview.CountdownView;
import com.jauker.widget.BadgeView;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import static com.efounder.utils.MallRequestUtil.CART_AMOUNT_URL;

/**
 * Created by will on 18-1-10.
 * vLayout组件各子组件的适配器帮助类
 */

public class BaseDelegateAdapterHelper {
    public static final int VIEW_TYPE_BANNER = 0;//011601
    public static final int VIEW_TYPE_GRID = 1;//021401
    public static final int VIEW_TYPE_RECYCLER = 2;//022401
    public static final int VIEW_TYPE_RECYCLER_WITH_PRICE = 3;//022101
    public static final int VIEW_TYPE_RECYCLER_WITH_BRAND = 4;//022201
    public static final int VIEW_TYPE_LIST_DAILY_SELECT = 5;//011401
    public static final int VIEW_TYPE_RECOMMEND_ITEM = 6;//023010
    public static final int VIEW_TYPE_RECOMMEND_RECYCLER = 7;//023011
    public static final int VIEW_TYPE_COUNT_DOWN_ITEM = 8;//023011
    public static final int VIEW_TYPE_ONE_PLUS_N_DAILY_NEW = 9;//021101
    public static final int VIEW_TYPE__GRID_TWO = 10;//020701//TYPE_GRID
    public static final int VIEW_TYPE_BANNER_ITEM = 11;//010901
    public static final int VIEW_TYPE_GRID_SINGLE_MARK = 12;//020201
    public static final int VIEW_TYPE_SNATCH_GOOD_ITEM = 16;//夺宝商品
    public static final int VIEW_TYPE_TIME_TO_BUY_ITEM = 17;//限时抢购

    //秒杀item
    public static final int VIEW_TYPE_SECKILL = 13;
    //一元购item
    public static final int VIEW_TYPE_ONE_YUAN_TO_BUY = 14;
    //l两列的
    public static final int VIEW_TYPE_TWO_SPAN_GRID= 15;

//    public static final int VIEW_TYPE_GRID_FOUR = 13;//021201 和TYPE_GRID一样？有必要区分？

    //cart购物车组件
    public static final int VIEW_TYPE_CART_NO_ITEM = 30;
    public static final int VIEW_TYPE_FLOAT_CART = 31;
    public static final int VIEW_TYPE_CHOOSE_ADDRESS = 32;
    public static final int VIEW_TYPE_CART_ITEM = 33;

    private Context mContext;

    public BaseDelegateAdapterHelper(Context mContext) {
        this.mContext = mContext;
    }

    public BaseDelegateAdapter getGridAdapter(final ItemList itemList) {
        int column = itemList.getItems().size();
        GridLayoutHelper gridLayoutHelper = new GridLayoutHelper(column);
        gridLayoutHelper.setPadding(0, 0, 0, 0);
        gridLayoutHelper.setVGap(0);// 控制子元素之间的垂直间距
        gridLayoutHelper.setHGap(0);// 控制子元素之间的水平间距
        gridLayoutHelper.setBgColor(mContext.getResources().getColor(R.color.contact_item_background_color));
        return new BaseDelegateAdapter(mContext, gridLayoutHelper, R.layout.item, column, VIEW_TYPE_GRID) {
            @Override
            public void onBindViewHolder(BaseViewHolder holder, final int position) {
                super.onBindViewHolder(holder, position);
                final List<BaseItem> items = itemList.getItems();
                ImageView imageView = (ImageView) holder.itemView;
                Glide.with(mContext)
                        .load(items.get(position).getImgUrl())
                        .apply(new RequestOptions().fitCenter()
//                            .error(R.drawable.loading_image_background)
                                .diskCacheStrategy(DiskCacheStrategy.ALL)
                                .skipMemoryCache(false))
                        .into(imageView);
                imageView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        Intent intent = new Intent(mContext, MallWebViewActivity.class);
                        Bundle bundle = new Bundle();
                        if (items.get(position).getIntent() != null) {
                            bundle.putString("urlstr", items.get(position).getIntent());
                            intent.putExtras(bundle);
                            ((Activity) mContext).startActivity(intent);
                        }
                    }
                });
            }
        };
    }

    public BaseDelegateAdapter getGridTwoAdapter(final ItemList itemList) {
        int column = itemList.getItems().size();
        GridLayoutHelper gridLayoutHelper = new GridLayoutHelper(column);
        gridLayoutHelper.setPadding(0, 0, 0, 0);
        gridLayoutHelper.setVGap(16);// 控制子元素之间的垂直间距
        gridLayoutHelper.setHGap(2);// 控制子元素之间的水平间距
        gridLayoutHelper.setBgColor(mContext.getResources().getColor(R.color.contact_item_background_color));
        return new BaseDelegateAdapter(mContext, gridLayoutHelper, R.layout.item, column, VIEW_TYPE__GRID_TWO) {
            @Override
            public void onBindViewHolder(BaseViewHolder holder, int position) {
                super.onBindViewHolder(holder, position);
                List<BaseItem> items = itemList.getItems();
                ImageView imageView = (ImageView) holder.itemView;
                Glide.with(mContext)
                        .load(items.get(position).getImgUrl())
                        .apply(new RequestOptions().fitCenter()
//                            .error(R.drawable.loading_image_background)
                                .diskCacheStrategy(DiskCacheStrategy.ALL)
                                .skipMemoryCache(false))
                        .into(imageView);
                Intent intent = new Intent(mContext, MallWebViewActivity.class);
                Bundle bundle = new Bundle();
                bundle.putString("urlstr", items.get(position).getIntent());
                intent.putExtras(bundle);
                ((Activity) mContext).startActivity(intent);
            }
        };
    }
    //两列的gridview
    public BaseDelegateAdapter getTwoSpanGridAdapter(final ItemList itemList) {
        int column = itemList.getItems().size();
        GridLayoutHelper gridLayoutHelper = new GridLayoutHelper(2);
        gridLayoutHelper.setPadding(0, 0, 0, 0);
        gridLayoutHelper.setVGap(16);// 控制子元素之间的垂直间距
        gridLayoutHelper.setHGap(16);// 控制子元素之间的水平间距
        //是否自动扩展
        gridLayoutHelper.setAutoExpand(false);
        gridLayoutHelper.setBgColor(mContext.getResources().getColor(R.color.contact_item_background_color));
        return new BaseDelegateAdapter(mContext, gridLayoutHelper, R.layout.item_two_span, column, VIEW_TYPE_TWO_SPAN_GRID) {
            @Override
            public void onBindViewHolder(BaseViewHolder holder, final int position) {
                super.onBindViewHolder(holder, position);
                final List<BaseItem> items = itemList.getItems();
                ImageView imageView = (ImageView) holder.getView(R.id.two_span_grid_image);
                TextView textView1 = (TextView) holder.getView(R.id.two_span_grid_tv1);
                TextView textView2 = (TextView) holder.getView(R.id.two_span_grid_tv2);
                textView1.setText(items.get(position).getName());
                textView2.setText(items.get(position).getPriceUnit() + " "+items.get(position).getCurrentPrice());
                Glide.with(mContext)
                        .load(items.get(position).getImgUrl())
                        .apply(new RequestOptions().fitCenter()
                                .diskCacheStrategy(DiskCacheStrategy.ALL)
                                .skipMemoryCache(false))
                        .into(imageView);
                imageView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(mContext, MallWebViewActivity.class);
                        Bundle bundle = new Bundle();
                        bundle.putString("urlstr", items.get(position).getIntent());
                        intent.putExtras(bundle);
                        ((Activity) mContext).startActivity(intent);
                    }
                });

            }
        };
    }

    public BaseDelegateAdapter getBannerAdapter(final ItemList itemList) {
        final List<String> urls = new ArrayList<>();
        for (BaseItem item : itemList.getItems()) {
            urls.add(item.getImgUrl());
        }
        return new BaseDelegateAdapter(mContext,
                new LinearLayoutHelper(), R.layout.layout_banner, 1, VIEW_TYPE_BANNER) {
            @Override
            public void onBindViewHolder(BaseViewHolder holder, int position) {
                super.onBindViewHolder(holder, position);
                Banner banner = (Banner) holder.getView(R.id.banner);
                if (banner.getImagesCount() == 0) {
                    //设置banner样式
                    banner.setBannerStyle(BannerConfig.CIRCLE_INDICATOR);
                    //焦点
                    banner.setFocusable(false);
                    //设置图片加载器
                    banner.setImageLoader(new GlideImageLoader());
                    //设置图片集合
                    banner.setImages(urls);
                    //设置banner动画效果
                    banner.setBannerAnimation(Transformer.Default);
                    //设置自动轮播，默认为true
                    banner.isAutoPlay(true);
                    //设置轮播时间
                    banner.setDelayTime(3000);
                    //设置指示器位置（当banner模式中有指示器时）
                    banner.setIndicatorGravity(BannerConfig.CENTER);
                    //banner设置方法全部调用完毕时最后调用
                    banner.start();
                    banner.setOnBannerListener(new OnBannerListener() {
                        @Override
                        public void OnBannerClick(int position) {
                            Intent intent = new Intent(mContext, MallWebViewActivity.class);
                            Bundle bundle = new Bundle();
                            if ("4".equals(itemList.getItems().get(position).getIntentType())) {
                                bundle.putString("urlstr", itemList.getItems().get(position).getIntent());
                                intent.putExtras(bundle);
                                ((Activity) mContext).startActivity(intent);
                            }
                        }
                    });
                }
            }
        };
    }

    public BaseDelegateAdapter getBannerItemAdapter(final ItemList itemList) {
        final List<String> urls = new ArrayList<>();
        for (BaseItem item : itemList.getItems()) {
            urls.add(item.getImgUrl());
        }
        return new BaseDelegateAdapter(mContext,
                new LinearLayoutHelper(), R.layout.layout_banner, 1, VIEW_TYPE_BANNER_ITEM) {
            @Override
            public void onBindViewHolder(BaseViewHolder holder, int position) {
                super.onBindViewHolder(holder, position);
                Banner banner = (Banner) holder.getView(R.id.banner);
                if (banner.getImagesCount() == 0) {
                    //设置banner样式
                    banner.setBannerStyle(BannerConfig.NOT_INDICATOR);
                    banner.setHasMultiPages(true);
                    //设置图片加载器
                    banner.setImageLoader(new GlideImageLoader());
                    //设置图片集合
                    banner.setImages(urls);
                    //设置banner动画效果
                    banner.setBannerAnimation(Transformer.Stack);
                    //设置自动轮播，默认为true
                    banner.isAutoPlay(false);
                    //banner设置方法全部调用完毕时最后调用
                    banner.start();
                    banner.setOnBannerListener(new OnBannerListener() {
                        @Override
                        public void OnBannerClick(int position) {
                            Intent intent = new Intent(mContext, MallWebViewActivity.class);
                            Bundle bundle = new Bundle();
                            bundle.putString("urlstr", itemList.getItems().get(position).getIntent());
                            intent.putExtras(bundle);
                            ((Activity) mContext).startActivity(intent);
                        }
                    });
                }
            }
        };
    }


    public BaseDelegateAdapter getScrollAdapter(final ItemList itemList) {
        return new BaseDelegateAdapter(mContext,
                new LinearLayoutHelper(), R.layout.layout_scroll, 1, VIEW_TYPE_RECYCLER) {
            @Override
            public void onBindViewHolder(BaseViewHolder holder, int position) {
                super.onBindViewHolder(holder, position);
                ImageView imageView = holder.getView(R.id.imageViewAbove);
                //设置图片
                Glide.with(mContext)
                        .load(itemList.getImageUrl())
                        .apply(new RequestOptions().centerCrop()
                                .diskCacheStrategy(DiskCacheStrategy.ALL)
                                .skipMemoryCache(false))
                        .into(imageView);
                imageView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        //跳转html
                    }
                });
                RecyclerView recyclerView = holder.getView(R.id.recyclerView);
                //设置布局管理器
                LinearLayoutManager linearLayoutManager = new LinearLayoutManager(mContext);
                linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
                recyclerView.setLayoutManager(linearLayoutManager);
                //设置适配器
                ScrollAdapter mAdapter = new ScrollAdapter(mContext, itemList.getItems(), R.layout.item_scroll);
                mAdapter.addFootView(new View(mContext));
                recyclerView.setAdapter(mAdapter);
            }
        };
    }

    public BaseDelegateAdapter getScrollWithBrandAdapter(final ItemList itemList) {
        return new BaseDelegateAdapter(mContext,
                new LinearLayoutHelper(), R.layout.layout_scroll, 1, VIEW_TYPE_RECYCLER_WITH_BRAND) {
            @Override
            public void onBindViewHolder(BaseViewHolder holder, int position) {
                super.onBindViewHolder(holder, position);
                ImageView imageView = holder.getView(R.id.imageViewAbove);
                //设置图片
                Glide.with(mContext)
                        .load(itemList.getImageUrl())
                        .apply(new RequestOptions().centerCrop()
                                .diskCacheStrategy(DiskCacheStrategy.ALL)
                                .skipMemoryCache(false))
                        .into(imageView);
                imageView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        //跳转html
                    }
                });
                RecyclerView recyclerView = holder.getView(R.id.recyclerView);
                //设置布局管理器
                LinearLayoutManager linearLayoutManager = new LinearLayoutManager(mContext);
                linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
                recyclerView.setLayoutManager(linearLayoutManager);
                //设置适配器
                ScrollAdapter mAdapter = new ScrollAdapter(mContext, itemList.getItems(), R.layout.item_scroll_brand);
                mAdapter.addFootView(new View(mContext));
                recyclerView.setAdapter(mAdapter);
            }
        };
    }

    public BaseDelegateAdapter getScrollWithPriceAdapter(final ItemList itemList) {
        return new BaseDelegateAdapter(mContext,
                new LinearLayoutHelper(), R.layout.layout_scroll, 1, VIEW_TYPE_RECYCLER_WITH_PRICE) {
            @Override
            public void onBindViewHolder(BaseViewHolder holder, int position) {
                super.onBindViewHolder(holder, position);
                ImageView imageView = holder.getView(R.id.imageViewAbove);
                //设置图片
                Glide.with(mContext)
                        .load(itemList.getImageUrl())
                        .apply(new RequestOptions().centerCrop()
                                .diskCacheStrategy(DiskCacheStrategy.ALL)
                                .skipMemoryCache(false))
                        .into(imageView);
                imageView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        //跳转html
                    }
                });
                RecyclerView recyclerView = holder.getView(R.id.recyclerView);
                //设置布局管理器
                LinearLayoutManager linearLayoutManager = new LinearLayoutManager(mContext);
                linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
                recyclerView.setLayoutManager(linearLayoutManager);
                //设置适配器
                ScrollAdapter mAdapter = new ScrollAdapter(mContext, itemList.getItems(), R.layout.item_scroll_price);
                mAdapter.addFootView(new View(mContext));
                recyclerView.setAdapter(mAdapter);
            }
        };
    }

    public BaseDelegateAdapter getSingleMarkAdapter(final ItemList itemList) {
        return new BaseDelegateAdapter(mContext, new LinearLayoutHelper(),
                R.layout.item_single_image, 1, VIEW_TYPE_GRID_SINGLE_MARK) {
            @Override
            public void onBindViewHolder(BaseViewHolder holder, int position) {
                super.onBindViewHolder(holder, position);
                ImageView imageView = (ImageView) holder.getView(R.id.single_image);
                Glide.with(mContext)
                        .load(itemList.getImageUrl())
                        .apply(new RequestOptions().fitCenter()
                                .diskCacheStrategy(DiskCacheStrategy.ALL)
                                .skipMemoryCache(false))
                        .into(imageView);
            }
        };
    }

    public BaseDelegateAdapter getDailyNewGridAdapter(final ItemList itemList) {
        OnePlusNLayoutHelper onePlusNLayoutHelper = new OnePlusNLayoutHelper();

        return new BaseDelegateAdapter(mContext, onePlusNLayoutHelper,
                R.layout.item_with_margin, 3, VIEW_TYPE_ONE_PLUS_N_DAILY_NEW) {
            @Override
            public void onBindViewHolder(BaseViewHolder holder, int position) {
                super.onBindViewHolder(holder, position);
                ImageView leftImageView = (ImageView) holder.getView(R.id.grid_image);
//                ImageView rightOneImageView = (ImageView) holder.getView(R.id.iv_right_one);
//                ImageView rightTwoImageView = (ImageView) holder.getView(R.id.iv_right_two);
                Glide.with(mContext)
                        .load(itemList.getItems().get(position).getImgUrl())
                        .apply(new RequestOptions().fitCenter()
                                .diskCacheStrategy(DiskCacheStrategy.ALL)
                                .skipMemoryCache(false))
                        .into(leftImageView);

            }
        };
    }

    public BaseDelegateAdapter getDailySelectListAdapter(final ItemList itemList) {
        int count = itemList.getItems().size();
        return new BaseDelegateAdapter(mContext, new LinearLayoutHelper(),
                R.layout.daily_select, count, VIEW_TYPE_LIST_DAILY_SELECT) {
            @Override
            public void onBindViewHolder(BaseViewHolder holder, int position) {
                super.onBindViewHolder(holder, position);
                TextView title = (TextView) holder.getView(R.id.tv_title);
                TextView item_title = (TextView) holder.getView(R.id.tv_item_title);
                TextView item_desc = (TextView) holder.getView(R.id.tv_desc);
                ImageView item_image = (ImageView) holder.getView(R.id.iv_select_item);
                title.setText(itemList.getTitle());
                if (position != 0) {
                    title.setVisibility(View.GONE);
                }
                item_title.setText(itemList.getItems().get(position).getTitle());
                item_desc.setText(itemList.getItems().get(position).getDesc());
                Glide.with(mContext)
                        .load(itemList.getItems().get(position).getImgUrl())
                        .apply(new RequestOptions().fitCenter()
                                .diskCacheStrategy(DiskCacheStrategy.ALL)
                                .skipMemoryCache(false))
                        .into(item_image);
            }
        };
    }

    public BaseDelegateAdapter getRecommendItemAdapter(final ItemList itemList) {

        return new BaseDelegateAdapter(mContext, new LinearLayoutHelper(),
                R.layout.item_recommend, 1, VIEW_TYPE_RECOMMEND_ITEM) {
            @Override
            public void onBindViewHolder(BaseViewHolder holder, int position) {
                super.onBindViewHolder(holder, position);
                TextView title = (TextView) holder.getView(R.id.recommend_title);
                TextView comment = (TextView) holder.getView(R.id.recommend_comment);
                TextView price = (TextView) holder.getView(R.id.recommend_item_price);
                ImageView item_image = (ImageView) holder.getView(R.id.iv_item_recommend);
                title.setText(itemList.getTitle());
                comment.setText(itemList.getIntro());
                price.setText(itemList.getPriceUnit() + " " + itemList.getPrice());
                Glide.with(mContext)
                        .load(itemList.getImageUrl())
                        .apply(new RequestOptions().fitCenter()
                                .diskCacheStrategy(DiskCacheStrategy.ALL)
                                .skipMemoryCache(false))
                        .into(item_image);
                holder.itemView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        Intent intent = new Intent(mContext, ProductDetailsActivity.class);
                        intent.putExtra("goodbh", itemList.getIntent());
                        mContext.startActivity(intent);
                    }
                });
            }
        };
    }

    public BaseDelegateAdapter getSnatchGoodItemAdapter(final ItemList itemList) {

        return new BaseDelegateAdapter(mContext, new LinearLayoutHelper(),
                R.layout.item_recommend, 1, VIEW_TYPE_SNATCH_GOOD_ITEM) {
            @Override
            public void onBindViewHolder(BaseViewHolder holder, int position) {
                super.onBindViewHolder(holder, position);
                TextView title = (TextView) holder.getView(R.id.recommend_title);
                TextView comment = (TextView) holder.getView(R.id.recommend_comment);
                TextView price = (TextView) holder.getView(R.id.recommend_item_price);
                ImageView item_image = (ImageView) holder.getView(R.id.iv_item_recommend);
                TextView tvGoodMark = holder.getView(R.id.tv_good_mark);
                if (itemList.getGoodMark() != null && !itemList.getGoodMark().equals("")) {
                    tvGoodMark.setVisibility(View.VISIBLE);
                    tvGoodMark.setText(itemList.getGoodMark());
                } else {
                    tvGoodMark.setVisibility(View.GONE);
                }
                title.setText(itemList.getTitle());
                comment.setText(itemList.getIntro());
                price.setTextColor(mContext.getResources().getColor(R.color.mall_color_orange));
                price.setText(itemList.getPriceUnit() + " " + itemList.getPrice());
                Glide.with(mContext)
                        .load(itemList.getImageUrl())
                        .apply(new RequestOptions().fitCenter()
                                .diskCacheStrategy(DiskCacheStrategy.ALL)
                                .skipMemoryCache(false))
                        .into(item_image);
                holder.itemView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        Intent intent = new Intent(mContext, ProductDetailsActivity.class);
                        intent.putExtra("goodbh", itemList.getIntent());
                        mContext.startActivity(intent);
                    }
                });
            }
        };
    }

    public BaseDelegateAdapter getTimeToBuyItemAdapter(final ItemList itemList) {

        return new BaseDelegateAdapter(mContext, new LinearLayoutHelper(),
                R.layout.item_recommend, 1, VIEW_TYPE_TIME_TO_BUY_ITEM) {
            @Override
            public void onBindViewHolder(BaseViewHolder holder, int position) {
                super.onBindViewHolder(holder, position);
                TextView title = (TextView) holder.getView(R.id.recommend_title);
                TextView comment = (TextView) holder.getView(R.id.recommend_comment);
                TextView price = (TextView) holder.getView(R.id.recommend_item_price);
                ImageView item_image = (ImageView) holder.getView(R.id.iv_item_recommend);
                TextView tvGoodMark = holder.getView(R.id.tv_good_mark);
                if (itemList.getGoodMark() != null && !itemList.getGoodMark().equals("")) {
                    tvGoodMark.setVisibility(View.VISIBLE);
                    tvGoodMark.setText(itemList.getGoodMark());
                } else {
                    tvGoodMark.setVisibility(View.GONE);
                }
                title.setText(itemList.getTitle());
                comment.setText(itemList.getIntro());
                price.setTextColor(mContext.getResources().getColor(R.color.mall_color_orange));
                price.setText(itemList.getPriceUnit() + " " + itemList.getPrice());
                Glide.with(mContext)
                        .load(itemList.getImageUrl())
                        .apply(new RequestOptions().fitCenter()
                                .diskCacheStrategy(DiskCacheStrategy.ALL)
                                .skipMemoryCache(false))
                        .into(item_image);
                holder.itemView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        Intent intent = new Intent(mContext, ProductDetailsActivity.class);
                        intent.putExtra("goodbh", itemList.getIntent());
                        mContext.startActivity(intent);
                    }
                });
            }
        };
    }

    public BaseDelegateAdapter getScrollWithRecommendAdapter(final ItemList itemList) {
        return new BaseDelegateAdapter(mContext,
                new LinearLayoutHelper(), R.layout.layout_scroll_recommend, 1, VIEW_TYPE_RECOMMEND_RECYCLER) {
            @Override
            public void onBindViewHolder(BaseViewHolder holder, int position) {
                super.onBindViewHolder(holder, position);
                TextView title = holder.getView(R.id.title);
                TextView albumDesc = holder.getView(R.id.albumDesc);
                TextView goodsNum = holder.getView(R.id.goodsNum);
                TextView buyerNum = holder.getView(R.id.buyerNum);
                final ImageView favor = holder.getView(R.id.favor);
                title.setText(itemList.getTitle());
                albumDesc.setText(itemList.getAlbumDesc());
                goodsNum.setText(itemList.getGoodsNum() + ResStringUtil.getString(R.string.mail_money_good));
                buyerNum.setText(itemList.getBuyerNum() + ResStringUtil.getString(R.string.mail_people_buy));
                if (itemList.getHasFavor()) {
                    favor.setImageDrawable(mContext.getResources().getDrawable(R.drawable.favor));
                } else {
                    favor.setImageDrawable(mContext.getResources().getDrawable(R.drawable.favor_no));
                }
                favor.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        if (itemList.getHasFavor()) {
                            itemList.setHasFavor(false);
                            favor.setImageDrawable(mContext.getResources().getDrawable(R.drawable.favor_no));
                        } else {
                            itemList.setHasFavor(true);
                            favor.setImageDrawable(mContext.getResources().getDrawable(R.drawable.favor));
                        }
                    }
                });
                RecyclerView recyclerView = holder.getView(R.id.recyclerView);
                //设置布局管理器
                LinearLayoutManager linearLayoutManager = new LinearLayoutManager(mContext);
                linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
                recyclerView.setLayoutManager(linearLayoutManager);
                //设置适配器
                ScrollAdapter mAdapter = new ScrollAdapter(mContext, itemList.getItems(), R.layout.item_scroll);
                mAdapter.addFootView(new View(mContext));
                recyclerView.setAdapter(mAdapter);
            }
        };
    }

    public BaseDelegateAdapter getCartNoItemAdapter() {
        return new BaseDelegateAdapter(mContext, new LinearLayoutHelper(), R.layout.layout_cart_no_item, 1,
                VIEW_TYPE_CART_NO_ITEM) {
            @Override
            public void onBindViewHolder(BaseViewHolder holder, int position) {
                super.onBindViewHolder(holder, position);
//                ImageView ivNewArrivals = (ImageView) holder.getView(R.id.iv_new_arrivals);
//                ImageView ivHotReports = (ImageView) holder.getView(R.id.iv_hot_reports);
//                ivNewArrivals.setOnClickListener(new View.OnClickListener() {
//                    @Override
//                    public void onClick(View view) {
//                        //todo
//                    }
//                });
//                ivHotReports.setOnClickListener(new View.OnClickListener() {
//                    @Override
//                    public void onClick(View view) {
//                        //todo
//
//                    }
//                });
            }
        };
    }


    public BaseDelegateAdapter getFloatAdapter() {
        FloatLayoutHelper layoutHelper = new FloatLayoutHelper();
        layoutHelper.setAlignType(FixLayoutHelper.BOTTOM_RIGHT);
        DisplayMetrics dm = mContext.getResources().getDisplayMetrics();
        int width = dm.widthPixels;
        int height = dm.heightPixels;
        layoutHelper.setDefaultLocation(9 / 10 * width, 9 / 10 * height);
        return new BaseDelegateAdapter(mContext, layoutHelper, R.layout.float_cart, 1, VIEW_TYPE_FLOAT_CART) {
            @Override
            public void onBindViewHolder(BaseViewHolder holder, int position) {
                super.onBindViewHolder(holder, position);
                FrameLayout ivFloatCart = (FrameLayout) holder.itemView;
                ImageView imageView = holder.getView(R.id.iv_float_cart);

                    //角标
                BadgeView bvFloatCartNum = holder.getView(R.id.bv_float_cart_num);

                initBadge(bvFloatCartNum);

                ivFloatCart.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        Intent intent = new Intent(mContext, MallCartOrderActivity.class);
                        mContext.startActivity(intent);
                    }
                });
            }
        };

    }

    public BaseDelegateAdapter getDividerAdapter() {
        return new BaseDelegateAdapter(mContext, new LinearLayoutHelper(), R.layout.mall_layout_divider, 1,
                66) {
            @Override
            public void onBindViewHolder(BaseViewHolder holder, int position) {
                super.onBindViewHolder(holder, position);
//                ImageView ivNewArrivals = (ImageView) holder.getView(R.id.iv_new_arrivals);
//                ImageView ivHotReports = (ImageView) holder.getView(R.id.iv_hot_reports);
//                ivNewArrivals.setOnClickListener(new View.OnClickListener() {
//                    @Override
//                    public void onClick(View view) {
//                        //todo
//                    }
//                });
//                ivHotReports.setOnClickListener(new View.OnClickListener() {
//                    @Override
//                    public void onClick(View view) {
//                        //todo
//
//                    }
//                });
            }
        };

    }

    /**
     * 地址选择组件
     *
     * @param isFromBottom 是否从底部弹出，否则从右侧弹出
     * @return adapter
     */
    public BaseDelegateAdapter getChooseAddressAdapter(final boolean isFromBottom) {
        return new BaseDelegateAdapter(mContext, new LinearLayoutHelper(), R.layout.choose_address, 1, VIEW_TYPE_CHOOSE_ADDRESS) {
            @Override
            public void onBindViewHolder(BaseViewHolder holder, int position) {
                super.onBindViewHolder(holder, position);
                LinearLayout linearLayout = (LinearLayout) holder.itemView;
                final TextView tvAddress = (TextView) holder.getView(R.id.tv_address);
                linearLayout.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        if (isFromBottom) {
                            BottomDialog dialog = new BottomDialog(mContext);
                            dialog.setOnAddressSelectedListener(new OnAddressSelectedListener() {
                                @Override
                                public void onAddressSelected(Province province, City city, County county, Street street) {
                                    tvAddress.setText(province.name + city.name);
                                }
                            });
                            dialog.show();
                        } else {
                            final RightDialog dialog = new RightDialog(mContext);
                            dialog.setOnAddressSelectedListener(new OnAddressSelectedListener() {
                                @Override
                                public void onAddressSelected(Province province, City city, County county, Street street) {
                                    tvAddress.setText(province.name + city.name);
                                    dialog.dismiss();
                                }
                            });
                            dialog.show();
                        }
                    }
                });
            }
        };
    }

    public BaseDelegateAdapter getCartItemsAdapter(final List<CartStore> cartStores) {
        return new BaseDelegateAdapter(mContext, new LinearLayoutHelper(), R.layout.cart_item, 1, VIEW_TYPE_CART_ITEM) {
            @Override
            public void onBindViewHolder(BaseViewHolder holder, int position) {
                super.onBindViewHolder(holder, position);
                MyExpandableListView expandableListView = (MyExpandableListView) holder.getView(R.id.expandablelist);
//                CartExpandableAdapter cartExpandableAdapter = new CartExpandableAdapter(cartStores, mContext);
//                expandableListView.setAdapter(cartExpandableAdapter);
                for (int i = 0; i < cartStores.size(); i++) {
                    expandableListView.expandGroup(i);
                }

            }
        };
    }

    /**
     * 秒杀item
     *
     * @param itemList 数据列表
     * @return item的adapter
     */
    /**
     * //模拟时间
     */
    private long time = 60*60 * 1000 + System.currentTimeMillis();

    public BaseDelegateAdapter getSeckillItem(final ItemList itemList) {

        return new BaseDelegateAdapter(mContext, new LinearLayoutHelper(), R.layout.mobilemall_recycler_item_recommend_seckill
                , 1, VIEW_TYPE_SECKILL) {

            @Override
            public void onBindViewHolder(BaseViewHolder holder, int position) {
                super.onBindViewHolder(holder, position);
                CountdownView countdownView = holder.getView(R.id.btn_countdown);
                refreshTime(countdownView, time - System.currentTimeMillis());
                //添加中间横线
                ((TextView)holder.getView(R.id.tv_original_price)).getPaint().setFlags(Paint. STRIKE_THRU_TEXT_FLAG );
                com.efounder.imageloader.GlideImageLoader.getInstance().displayRoundCornerImage(mContext, (ImageView) holder.getView(R.id.iv_goods_image)
                        ,"http://haitao.nos.netease.com/8K49wCv0hUkM5CXIcMuKNCMWTapxdZkXoutput_1T1803012004_500_500T1803012019_500_500.jpg"
                        ,R.mipmap.default_img,R.mipmap.default_img,20);
            }

            /**
             * 以下两个接口代替 activity.onStart() 和 activity.onStop(), 控制 timer 的开关
             */
            @Override
            public void onViewAttachedToWindow(BaseViewHolder holder) {
//                int pos = holder.getAdapterPosition();
//                LogUtils.e(String.format("mCvCountdownView %s is attachedToWindow", pos));

                refreshTime((CountdownView) holder.getView(R.id.btn_countdown), time - System.currentTimeMillis());
            }

            @Override
            public void onViewDetachedFromWindow(BaseViewHolder holder) {
//                int pos = holder.getAdapterPosition();
//                LogUtils.e(String.format("mCvCountdownView %s is detachedFromWindow", pos));

                ((CountdownView) holder.getView(R.id.btn_countdown)).stop();
            }

            /**
             * 时间刷新
             * @param countdownView  定时器控件
             * @param leftTime 时间
             */
            public void refreshTime(CountdownView countdownView, long leftTime) {
                if (leftTime > 0) {
                    countdownView.start(leftTime);
                } else {
                    countdownView.stop();
                    countdownView.allShowZero();
                }
            }

        };
    }

    /**
     * 一元购类型的item
     * @param itemList
     * @return
     */
    public BaseDelegateAdapter getOneYuanToBuyItem(ItemList itemList){
        return new BaseDelegateAdapter(mContext, new LinearLayoutHelper()
                , R.layout.mobilemall_recycler_item_recommend_one_yuan_to_buy, 1, VIEW_TYPE_ONE_YUAN_TO_BUY) {

            @Override
            public void onBindViewHolder(BaseViewHolder holder, int position) {
                super.onBindViewHolder(holder, position);
                //添加中间横线
                ((TextView)holder.getView(R.id.tv_original_price)).getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG );
                com.efounder.imageloader.GlideImageLoader.getInstance().displayRoundCornerImage(mContext, (ImageView) holder.getView(R.id.iv_goods_image)
                        ,"http://haitao.nos.netease.com/IiswiTAu9KUSl1KXfoRSEld000n9D6b2output_2T1803012004_500_500T1803012019_500_500.jpg"
                        ,R.mipmap.default_img,R.mipmap.default_img,20);
            }
        };
    }

    /**
     * 获取购物车的数量
     * @param
     */
    private void initBadge(final BadgeView bvFloatCartNum) {
        HashMap<String, String> map = new HashMap<>();
        map.put("userId", EnvironmentVariable.getUserName());
        MallRequestUtil.getRequest("", CART_AMOUNT_URL, map, new MallRequestUtil.MallRequestCallback() {

            @Override
            public void onSuccess(String response) {
                try {
                    JSONObject jsonObject = new JSONObject(response);
                    if (jsonObject.has("goodTotalCount")) {
                       int count = jsonObject.getInt("goodTotalCount");
                       if(bvFloatCartNum!=null){
                           if (count > 0 ) {
                               bvFloatCartNum.setVisibility(View.VISIBLE);
                               bvFloatCartNum.setText(count + "");
                           }else {
                               bvFloatCartNum.setVisibility(View.GONE);

                           }
                       }

                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFail(String error) {

            }
        });
    }

}
